<?php

class home extends model {

    function __construct() {
        parent::__construct(Controller::$a_con);
    }

    function get_def_info() {
        return $this->get_Results($this->con->select_query('SELECT * FROM web_def', 'web_info'));
    }

    function get_info_web($id) {
        return $this->get_Results($this->con->select_query('SELECT * FROM web_info WHERE id=' . $id, 'web_info'));
    }

    function get_menu() {
        return $this->get_Results($this->con->select_query('SELECT tag,title FROM web_info', 'web_info'));
    }

    function get_comment($id) {
        return $this->get_Results($this->con->select_query('SELECT com_email,com_con FROM comment WHERE temp_id='.$id.' ORDER BY com_id DESC', 'web_info'));
    }

    function get_menu_tag() {
        return $this->get_ResultA_One($this->con->select_query('SELECT tag FROM web_info', 'web_info'), MYSQLI_NUM);
    }

    function get_categories() {
        return $this->get_Results($this->con->select_query('SELECT id,cat_name,file_img FROM categories', 'web_info'));
    }

    function get_template($id, $begin = 0, $range = 5) {
        return $this->get_Results($this->con->select_query('SELECT temp.id,file_temp_255xX,price,file_temp,temp_dis,ctg.cat_name,temp.id_cat FROM  template AS temp INNER JOIN categories AS ctg ON temp.id_cat=ctg.id WHERE ' . ($id !== '' ? ('id_cat="' . $id . '"'.($id!=0 ? 'id_cat!=0' : '')) : '1=1') . ' ORDER BY temp_date LIMIT ' . $begin . ',' . $range, 'web_info'));
    }

    function get_temp_img($id) {
        return $this->get_ResultA_One($this->con->select_query('SELECT id,file_temp FROM template WHERE id=' . $id, 'get_temp_img'));
    }

    function get_temp_info($id) {
        return $this->get_ResultA_One($this->con->select_query('SELECT temp.*,ctg.cat_name FROM template AS temp INNER JOIN categories AS ctg ON temp.id_cat=ctg.id WHERE temp.id=' . $id, 'web_info'));
    }

    function get_bill_info($id) {
        return $this->get_ResultA_One($this->con->select_query('SELECT temp.id,temp.price,ctg.cat_name FROM template AS temp INNER JOIN categories AS ctg ON temp.id_cat=ctg.id WHERE temp.id=' . $id, 'web_info'));
    }

    function get_news($id) {
        return $this->get_ResultA_One($this->con->select_query('SELECT * FROM news WHERE id=' . $id, 'web_info'));
    }

    function get_allNews($begin = 0, $range = 5) {
        return $this->get_Results($this->con->select_query('SELECT id,news_title,file_news,news_dis,news_date FROM news ORDER BY news_date DESC LIMIT ' . $begin . ',' . $range, 'web_info'));
    }

    function news_count() {
        return $this->get_Results($this->con->select_query('SELECT count(id) FROM news', 'web_info'));
    }

}
